#ifndef __DICTIONARY_H__
#define __DICTIONARY_H__
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits>
#include <fstream>
#include <sstream>
using namespace std;

class Dictionary {
public:
    static Dictionary* createInstance() {
        pthread_once(&_once,init);
        return _pInstance;
    }

    static void init() {
        _pInstance = new Dictionary();
        //_dictType = 0;
        atexit(destroy);
    }
    static void destroy(){
        if(_pInstance){
            delete _pInstance;
            _pInstance = nullptr;
        }
    }   
    void setData(const string& dictPath, const string& indexPath);
    void setDictType(int val);
    int getDictType();
    vector<pair<string, int>>& getDict();
    map<string, set<int>>& getIndexTable();
    string doQuery(string word);

private:
    Dictionary(){
        //cout <<"Dictionary()" <<endl;
    }
    ~Dictionary(){
        //cout <<"~Dictionary()" <<endl;
    }
    Dictionary(const Dictionary &rhs);
    Dictionary &operator=(const Dictionary &rhs);
    static int _dictType;//初始为0,英文为1,中文为3
    vector<pair<string, int>> _dict;
    map<string, set<int>> _indexTable;
    static pthread_once_t _once;
    static Dictionary *_pInstance;
};

#endif
